<?php
require_once 'class/db/dbFaseStap.php';

/**
 * Description of FaseStap
 *
 * @author GHoogendoorn
 * @version 0.1
 * 
 * Version history
 * 0.1  GHoogendoorn    Initial version
 */
class FaseStap {
    
    private $fase_stap_naam = '';
    private $fase_stap_order = 0;
    private $fase_id;
    private $fase_stap_id;
    

    public function __construct($id = '') {
        //Initialisatie
        if (!empty($id)){
            $this->selectById($id);
        }
        
        
    }
    public function getFaseId() {
        return $this->fase_id;
    }

    public function setFaseId($fase_id) {
        $this->fase_id = $fase_id;
    }

    public function getFaseStapId() {
        return $this->fase_stap_id;
    }
    
    /**
     *
     * @param int $id   The id of the fase that belongs to the steps
     * @return array containing all the step_id's for the Fase $id.
     * 
     */
    public function getFaseStapIdList($id){
        $return_array = array();
        
        $db = new DbFaseStap;
        /** 
         * Read array as in:
         *  [0] => (StepId, Step name)
         */
        $return_array = $db->getFaseStapIdsForFase();

        
        /**
         * Change array to:
         * [StepId] = stepname
         */
        $step_id_array = array();
        
        foreach( $return_array as $idx => $data_array){
            
            $step_id_array[$data_array['fase_stap_id']] = $data_array['fase_stap_naam'];
        }
        
        return $step_id_array;
    }

    public function setFaseStapId($fase_stap_id) {
        $this->fase_stap_id = $fase_stap_id;
    }

    public function setName($name){
        if (is_string($name)){
            $this->fase_stap_naam = $name;
        }
    }
    
    public function setOrder($order){
        if (is_numeric($order)){
            $this->fase_stap_order = $order;
        }
    }
    
    public function save(){
        try{
            if ( empty($this->name)){
                throw new Exception('Set Step name before save');
            }
            if ( strlen($this->order) < 1 ){
                throw new Exception('Set Order before save');
            }
      
            
        }
        catch (Exception $e){
            trigger_error($e->getMessage() );
            trigger_error($e->getTraceAsString() );
        }
        
    }
    
    /**
     *
     * @param int $id Id of the current fase step 
     */
    private function selectById($id){
        
        $db = new DbFaseStap($id);
        $this->fase_id = $db->getFaseId();
        $this->fase_stap_id = $id;
        $this->fase_stap_naam = $db->getFase();
        $this->fase_stap_order = $db->getOrder();
        
    }
    

}

class TestFaseStap {

    public function TestFaseStap() {
        try {
            $test = new FaseStap();
            $test2 = new FaseStap('Dit is de fasestap naam', 1);
            
            
            //*
            echo __FILE__.__LINE__.__FUNCTION__.'<br />';
            echo '<pre>';
            var_dump($test);
            echo '</pre>';
            //*/
            
        } catch (Exception $e) {
            echo '<pre>';
            echo $e->getTraceAsString();
            echo '</pre>';
            trigger_error($e->getMessage());
        }
    }

}
?>
